/**
 *  This file is part of MunchLevel.
 *
 *  MunchLevel is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  MunchLevel is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with MunchLevel.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.munchlevel.view.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;

import com.astuetz.viewpager.extensions.SwipeyTabButton;
import com.astuetz.viewpager.extensions.TabsAdapter;
import com.munchlevel.R;
import com.munchlevel.data.GameInfo;

public class MultiSwipeyTabsAdapter implements TabsAdapter {

	private static final int VIEWS_PER_PAGE = 3;

	private Activity mContext;

	private GameInfo gameInfo;

	public MultiSwipeyTabsAdapter(Activity ctx, GameInfo gameInfo) {
		this.mContext = ctx;
		this.gameInfo = gameInfo;
	}

	@Override
	public View getView(int position) {
		SwipeyTabButton tab;

		LayoutInflater inflater = mContext.getLayoutInflater();
		tab = (SwipeyTabButton) inflater.inflate(R.layout.tab_swipey, null);

		int startIndex = (int) (position * VIEWS_PER_PAGE);

		for (int i = 0; i < VIEWS_PER_PAGE; i++) {
			if (i != 0)
				tab.append(" / ");
			if (startIndex + i < gameInfo.getPlayers()) {
				tab.append(gameInfo.getPlayer(startIndex + i).getName());
			} else {
				break;
			}

		}

		return tab;
	}

}
